import '../base/utils/nd_cache.dart';
import '../constants.dart';
import '../env_config.dart';

///
///Author: YoungChan
///Date: 2019/8/28 17:11
///Description: 服务器信息管理
///

class NDHostManager {
  static const _cacheGroup = "NDHostManager";

  ///缓存自定义服务器地址
  static void setCurrentHost(String? host) {
    if (host?.isNotEmpty == true) {
      NDCache.setString(_cacheGroup, customHostKey, host);
    } else {
      NDCache.remove(_cacheGroup, customHostKey);
    }
  }

  ///获取缓存的自定义服务器地址
  static Future<String> get currentHost async {
    var host = await NDCache.getString(_cacheGroup, customHostKey) ??
        EnvConfig.defaultHost;
    return Future.value(host);
  }

  ///缓存代理地址
  static void setProxyHost(String? host) {
    if (host?.isNotEmpty == true) {
      NDCache.setString(_cacheGroup, proxyHostKey, host);
    } else {
      NDCache.remove(_cacheGroup, proxyHostKey);
    }
  }

  ///获取缓存代理地址
  static Future<String?> get proxyHost async {
    return NDCache.getString(_cacheGroup, proxyHostKey);
  }
}
